﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Web.Script.Serialization;
using 文件传PDA工具;
using OpenFTP;

namespace YZZ
{
    class InformationController
    {
        public static void SaveTable(string Filename, DataTable table)
        {
            JSON json = new JSON(table);
            FileHelperTemplate.WriteFile(Filename, json.GetJSONArray());
        }
        public static DataTable LoadTable(string Filename)
        {
            DataTable result = new DataTable();
            result.Columns.Add("项目名称", typeof(string));
            result.Columns.Add("项目内容", typeof(string));
            JSON json = new JSON();
            string read = FileHelperTemplate.ReadFile(Filename);
            if (string.IsNullOrEmpty(read))
            {
                return result;
            }
            JavaScriptSerializer JSS = new JavaScriptSerializer();
            object obj = JSS.DeserializeObject(read);
            object[]loaded = JSON.JsonArrayAnalyze(obj);
            if (loaded.Length > 0)
            {
                foreach (object line in loaded)
                {
                    DataRow row = result.NewRow();
                    Dictionary<string, object> o = JSON.JsonObjectFromArrayAnalyze(line);
                    foreach (KeyValuePair<string, object> item in o)
                    {
                        row[item.Key] = item.Value;
                    }
                    result.Rows.Add(row);
                }
            }
            return result;
        }

        internal static void 上传文件(Form1 form1)
        {
            
        }
    }
}
